#if !defined(_FEATSELECT_H_INCLUDED_)
#define _FEATSELECT_H_INCLUDED_


#include <sys/types.h>
#include <cstring>

#include <queue>

#include <opencv2/opencv.hpp>
#include <opencv2/flann/config.h>

#include <opencv2/legacy/legacy.hpp>            // EM
#include <opencv2/contrib/contrib.hpp>          // colormap
#include <opencv2/nonfree/nonfree.hpp>          // SIFT

#include <sstream>
#include <fstream>

using namespace cv;
using namespace std;

class LC_Feature_Selection
{

	public:
		FILE * out;

		string fname;

	public:
		
		int FOLD_WHEN_SELECTING;
		int FOLD_WHEN_TEST;
		int FEAT_CAND_ONCE;

	LC_Feature_Selection(){
		fname = "log.txt";
		FOLD_WHEN_SELECTING = 10;
		FOLD_WHEN_TEST = 5;
		FEAT_CAND_ONCE = 50;
	}
	

	double get_acc(Mat & feature, Mat & label , int k = 5);

	double get_acc_cross(Mat & feature_t, Mat & label_t,Mat & feature, Mat & label, int k=5);

	void get_bag(Mat & feature, Mat & label, CvRTrees & bag);

	double get_res(Mat & feature, Mat & label, CvRTrees & bag, Mat & predict_value);

	void get_acc_on_feat(Mat & feature, Mat & label, std::vector<int> & select_id, double * & acc_on_feat, int n = 25);

	void appendfeature(Mat & all_feature, Mat & feature, std::vector<int> & select_id);

	void feature_selection(Mat & train_feature,Mat & train_label, Mat & test_feature, Mat & test_label,
						   std::vector<int> & select_id );

	void work(Mat & feature, Mat & label, string filename);

	void swapMatrix(Mat & feature , Mat & label);

	void feature_selection( 
		Mat & sele_feature,
		Mat & sele_label,
		Mat & train_feature,
		Mat & train_label,
		std::vector<Mat> & test_feature,
		std::vector<Mat> & test_label,
		std::vector<int> & select_id );

	void model_selection( 
		Mat & sele_feature,
		Mat & sele_label,
		Mat & train_feature,
		Mat & train_label,
		std::vector<Mat> & test_feature,
		std::vector<Mat> & test_label,
		std::vector<int> & select_id );

	void init(Mat & train_feature,Mat & train_label, Mat & test_feature, Mat & test_label);

	void get_acc_on_model(Mat & feature, Mat & label,
		std::vector<int> & mod_select_id ,  double * & acc_on_model, 
		int model_n, int * belongid, int feature_n);

	void get_feature_id_from_model(
	std::vector<int> & mod_select_id,
	std::vector<int> & select_id,
	int * belongid,
	int feature_n);
};



#endif // !defined(_FEATSELECT_H_INCLUDED_)
